package aof.biz;

import android.content.Context;
import java.util.ArrayList;

import aof.model.M_COSTDAY;
import aof.helper.MyDBHelper;


/**
 * Created by AOF on 1/6/2556.
 */
public class M_COSTDAY_BIZ extends MyDBHelper {
    public M_COSTDAY_BIZ(Context context) {
        super(context);
    }
    public ArrayList<M_COSTDAY> GetAll() {
        try {
            ArrayList<M_COSTDAY> MyArrList = new ArrayList<M_COSTDAY>();
            openDataBase();
            if (Query("SELECT * FROM M_COSTDAY ORDER BY YEAR DESC, MONTH DESC, DAY DESC")) {
                do {
                    M_COSTDAY model = new M_COSTDAY();
                    model.setOID(getDataString("OID"));
                    model.setDAY(getDataInt("DAY"));
                    model.setMONTH(getDataInt("MONTH"));
                    model.setYEAR(getDataInt("YEAR"));
                    model.setTOTAL(getDataDouble("TOTAL"));
                    model.setINCOME(getDataDouble("INCOME"));
                    model.setEXPENDITURE(getDataDouble("EXPENDITURE"));
                    model.setBALANCE(getDataDouble("BALANCE"));
                    model.setMINUS(getDataString("MINUS"));
                    model.setActive(getDataString("Active"));
                    model.setCreate_By(getDataString("Create_By"));
                    model.setCreate_Date(getDataString("Create_Date"));
                    model.setUpdate_By(getDataString("Update_By"));
                    model.setUpdate_Date(getDataString("Update_Date"));
                    MyArrList.add(model);
                } while (IsReadData());
            }
            return MyArrList;

        } catch (Exception e) {
            return null;
        } finally {
            closeDataBase();
        }
    }

    public ArrayList<M_COSTDAY> GetAll(int limit, int offset) {
        try {
            ArrayList<M_COSTDAY> MyArrList = new ArrayList<M_COSTDAY>();
            openDataBase();
            String strSql = "SELECT\n" +
                    "\t(\n" +
                    "\t\tSELECT\n" +
                    "\t\t\tCOUNT(1)\n" +
                    "\t\tFROM\n" +
                    "\t\t\tM_COSTDAY t2\n" +
                    "\t\tWHERE\n" +
                    "\t\t\tCAST (t2.OID AS INTEGER) >= CAST (t1.OID AS INTEGER)\n" +
                    "\t) AS ROWNUM,\n" +
                    "\tt1.*\n" +
                    "FROM\n" +
                    "\tM_COSTDAY t1\n" +
                    "ORDER BY\n" +
                    "\tt1.YEAR DESC,\n" +
                    "\tt1.MONTH DESC,\n" +
                    "\tt1.DAY DESC"
                    + " LIMIT "
                    + Integer.toString(limit) + " OFFSET "
                    + Integer.toString(offset);
            if (Query(strSql)) {
                do {
                    M_COSTDAY model = new M_COSTDAY();
                    model.setROWNUM(getDataInt("ROWNUM"));
                    model.setOID(getDataString("OID"));
                    model.setDAY(getDataInt("DAY"));
                    model.setMONTH(getDataInt("MONTH"));
                    model.setYEAR(getDataInt("YEAR"));
                    model.setTOTAL(getDataDouble("TOTAL"));
                    model.setINCOME(getDataDouble("INCOME"));
                    model.setEXPENDITURE(getDataDouble("EXPENDITURE"));
                    model.setBALANCE(getDataDouble("BALANCE"));
                    model.setMINUS(getDataString("MINUS"));
                    model.setActive(getDataString("Active"));
                    model.setCreate_By(getDataString("Create_By"));
                    model.setCreate_Date(getDataString("Create_Date"));
                    model.setUpdate_By(getDataString("Update_By"));
                    model.setUpdate_Date(getDataString("Update_Date"));
                    MyArrList.add(model);
                } while (IsReadData());
            }
            return MyArrList;

        } catch (Exception e) {
            return null;
        } finally {
            closeDataBase();
        }
    }
}
